#!/bin/bash

ROOT=`readlink -f "$0"`
ROOT=${ROOT:0:${#ROOT}-4}

EXT=`cat $ROOT/extension`

CP="$ROOT/lib/oberon-compiler.jar:$ROOT/lib/antlr-4.1-complete.jar"

BNRZ="$ROOT/lib/binary-files.jar"
BNRZ_RES=`java -jar "$BNRZ" -t "$1.$EXT"`


if [[ "$BNRZ_RES" == "binarize" ]]
then
    java -jar "$BNRZ" -e | java -cp "$CP" OberonCompiler "$1.$EXT"
else
    java -cp "$CP" OberonCompiler "$1.$EXT"
fi
